package com.unlcn.ils.kas.controller.order;

import com.unlcn.ils.kas.dao.model.order.OrderOtd;
import com.unlcn.ils.kas.service.order.OrderOtdService;
import com.unlcn.ils.kas.service.util.BaseException;
import com.unlcn.ils.kas.service.util.DateUtils;
import com.unlcn.ils.kas.vo.KasCustomerVO;
import com.unlcn.ils.kas.vo.RestVO;
import org.apache.commons.collections4.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * 微信端查询订单状态
 */
@RestController
@RequestMapping(value = "/otd")
public class OtdController {

    private static final Logger logger = LoggerFactory.getLogger(OtdController.class);

    @Autowired
    private OrderOtdService orderOtdService;

    @RequestMapping(value = "/getWaybillCode")
    @GetMapping
    public RestVO<Object> getWaybillCode(String waybillCode) {
        RestVO<Object> result = new RestVO<>(0, null, "查询订单信息成功");
        try {
            List<OrderOtd> otdList = orderOtdService.getKasOrderOtdByCustomerOtdList(waybillCode);
//            List<KasCustomerVO> voList = new ArrayList<>();
//            if (CollectionUtils.isNotEmpty(otdList)) {
//                otdList.forEach(otd -> {
//                            KasCustomerVO vo = new KasCustomerVO();
//                            vo.setCustomerOrderCode(otd.getCustomerOrderNo());
//                            vo.setOrderCode(otd.getSysOrderNo());
//                            vo.setOnWayLocation(otd.getNewestPosition());
//                            vo.setTransportType(otd.getTransportType());
//                            vo.setVehicleVin(otd.getVin());
//                            vo.setVehicleName(otd.getStyleName());
//                            vo.setOrderCode(otd.getOrderStatus());
//                            vo.setShipmentTime(Objects.equals(otd.getLeaveTime(), null) ? "" : DateUtils.getStringFromDate(otd.getLeaveTime(), "yyyy-MM-dd"));
//                            vo.setArriveTime(Objects.equals(otd.getShiptoTime(), null) ? "" : DateUtils.getStringFromDate(otd.getShiptoTime(), "yyyy-MM-dd"));
//                            vo.setInBoundUnlcn(Objects.equals(otd.getInboundTime(), null) ? "" : DateUtils.getStringFromDate(otd.getInboundTime(), "yyyy-MM-dd"));
//                            vo.setOutBoundUnlcn(Objects.equals(otd.getOutboundTime(), null) ? "" : DateUtils.getStringFromDate(otd.getOutboundTime(), "yyyy-MM-dd"));
//                            voList.add(vo);
//                        });
//            }
            result.setData(otdList);
        } catch (Exception e) {
            logger.error("OTDController.getWaybillCode", e);
            throw new BaseException(e.getMessage());
        }
        return result;
    }


}
